package com.zznj.xzjc.adapter.index;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zznj.xzjc.R;
import com.zznj.xzjc.bean.index.MyCollectData;
import com.zznj.xzjc.utils.StringUtils;
import com.zznj.xzjc.utils.TimeUtils;

import java.util.List;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/7
 */
public class MyCollectAdapter extends BaseQuickAdapter<MyCollectData, BaseViewHolder> {

    private String searchType;
    public MyCollectAdapter(int layoutResId, @Nullable List<MyCollectData> data, String searchType) {
        super(layoutResId, data);
        this.searchType = searchType;
    }

    private String key;
    public void setKey(String key){
        this.key = key;
        notifyDataSetChanged();
    }

    private String[] mTitle = {"全部", "线索", "知识库", "工作信息", "案源"};
    private String[] mValue = {"", "clue", "knowledgeLib", "notice", "case"};

    @Override
    protected void convert(BaseViewHolder helper, MyCollectData item) {
        if(StringUtils.isEmpty(key)){
            helper.setText(R.id.tv_title, StringUtils.delHtmlTags(item.getTitle()));
        }else{
            helper.setText(R.id.tv_title, Html.fromHtml(StringUtils.delHtmlTags(item.getTitle()).replace(key,"<span style='color:red;'>"+key+"</span>")));
        }
        helper.setText(R.id.tv_date, TimeUtils.getTime(item.getCollectTime(), "yyyy-MM-dd HH:mm:ss"));
        ImageView logo = helper.getView(R.id.tv_logo);

        Bundle bundle = new Bundle();
        bundle.putString("id", item.getInfoId() + "");

        if ("knowledgeLib".equals(item.getCollectType())) {
            logo.setImageResource(R.mipmap.gyss_sc_zhishiku_img);
            helper.setText(R.id.tv_leixing,"知识库");
        } else if ("notice".equals(item.getCollectType())) {
            logo.setImageResource(R.mipmap.gyss_sc_work_img);
            helper.setText(R.id.tv_leixing,"工作信息");
        } else if ("case".equals(item.getCollectType())) {
            logo.setImageResource(R.mipmap.gyss_sc_anyuan_img);
            helper.setText(R.id.tv_leixing,"案源");
        } else {
            logo.setImageResource(R.mipmap.gyss_sc_xiansuo_img);
            helper.setText(R.id.tv_leixing,"线索");
        }
        View logoLinear = helper.getView(R.id.logoLinear);
        if(StringUtils.isEmpty(searchType)){
            logoLinear.setVisibility(View.VISIBLE);
        }else{
            logoLinear.setVisibility(View.GONE);
        }
    }
}
